home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / grafik / converter / limbo4.0 / src / 3d / allocate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  16.1 KB  |  557 lines

  1. #include "includes.h"
  2.  
  3. /**************************************|****************************************
  4. Routine   : GimmeAPoolNode
  5. Input  par: none
  6. Output par: PoolNode * (pointer to PoolNode)
  7. Function  : Allocates a PoolNode structure. Initializes Next in 
  8.             structure PoolNode to zero.
  9. ***************************************|***************************************/
  10.  
  11.  PoolNode *GimmeAPoolNode(void)
  12.   {
  13.    PoolNode *p=(PoolNode *)malloc(sizeof(PoolNode));
  14.    if (p==NULL) 
  15.    ErrorHandler(NO_FREE_MEMORY,"GimmeAPoolNode not able to allocate structure");
  16.    p->x=p->y=p->z=0;
  17.    p->Features=NULL; /* initialize */
  18.    p->Distance=NULL;
  19.    p->Index=NULL;
  20.    p->Next=NULL;
  21.    return p;
  22.   }
  23.  
  24. /**************************************|****************************************
  25. Routine   : FreeMeAPoolNode"
  26. Input  par: PoolNode *El (pointer to PoolNode) 
  27. Output par: none
  28. Function  : Frees a PoolNode structure.
  29. ***************************************|***************************************/
  30.  
  31.  void FreeMeAPoolNode(PoolNode *p)
  32.   {
  33.    if (p==NULL) ErrorHandler(NULL_POINTER,"FreeMeAPoolNode with null pointer");
  34.    free(p);
  35.   }
  36.  
  37. /**************************************|****************************************
  38. Routine   : GimmeAPoolStructure"
  39. Input  par: none
  40. Output par: PoolStructure * (pointer to PoolStructure)
  41. Function  : Allocates a PoolStructure. Initializes pointers to Edges,
  42.             Shadesto null and B, D = 0.
  43. ***************************************|***************************************/
  44.  
  45.  PoolStructure *GimmeAPoolStructure(void)
  46.   {
  47.    PoolStructure *p=(PoolStructure *)malloc(sizeof(PoolStructure));
  48.    if (p==NULL) 
  49.    ErrorHandler(NO_FREE_MEMORY,"GimmeAPoolStructure not able to allocate structure");
  50.    p->DomainNodes=p->RangeNodes=NULL;
  51.    p->Next=NULL;
  52.    p->D=p->B=0;
  53.    return p;
  54.   }
  55.  
  56. /**************************************|****************************************
  57. Routine   : FreeMeAPoolStructure"
  58. Input  par: PoolStructure *p (pointer to PoolStructure) 
  59. Output par: none
  60. Function  : Frees a PoolStructure.
  61. ***************************************|***************************************/
  62.  
  63.  void FreeMeAPoolStructure(PoolStructure *p)
  64.   {
  65.    if (p==NULL) ErrorHandler(NULL_POINTER,"FreeMeAPoolStructure with null pointer");
  66.    free(p);
  67.   }
  68.  
  69. /**************************************|****************************************
  70. Routine   : GimmeAPoolNodeArray"
  71. Input  par: int xsize (x size of PoolNodearray)
  72.             int ysize (y size of PoolNodearray)
  73. Output par: PoolNode ***  (pointer to 2D array of PoolNode-pointers)
  74. Function  : Allocates a 2D structure of Poolnodes. No Initializing.
  75. ***************************************|***************************************/
  76.  
  77.  PoolNode ****GimmeAPoolNodeArray3D(int xsize,int ysize,int zsize)
  78.   {
  79.    int i,j;
  80.    PoolNode ****Array;
  81.    
  82.    Array=(PoolNode ****) calloc(xsize,sizeof(PoolNode ***));
  83.    if (Array==NULL) 
  84.    ErrorHandler(NO_FREE_MEMORY,"GimmeAPoolNodeArray3D not able to allocate struture");
  85.    for (i=0;i<xsize;i++)
  86.     {
  87.      Array[i]=(PoolNode ***) calloc(ysize,sizeof(PoolNode **));
  88.      if (Array[i]==NULL) 
  89.      ErrorHandler(NO_FREE_MEMORY,"GimmeAPoolNodeArray3D not able to allocate structure");
  90.      for (j=0;j<ysize;j++)
  91.       {
  92.        Array[i][j]=(PoolNode **) calloc(zsize,sizeof(PoolNode *));
  93.        if (Array[i][j]==NULL) 
  94.        ErrorHandler(NO_FREE_MEMORY,"GimmeAPoolNodeArray3D not able to allocate structure");
  95.       }
  96.     }
  97.    return Array;
  98.   }
  99.  
  100. /**************************************|****************************************
  101. Routine   : FreeMeAPoolNodeArray"
  102. Input  par: PoolArray *p (pointer to PoolNodeArray)
  103.             int xsize    (xsize of array) 
  104. Output par: none
  105. Function  : Frees a PoolNodeArray Node.
  106. ***************************************|***************************************/
  107.  
  108.  void FreeMeAPoolNodeArray3D(PoolNode ****p,int xsize,int ysize)
  109.   {
  110.    register unsigned int i,j;
  111.    
  112.    if (p==NULL) ErrorHandler(NULL_POINTER,"FreeMeAPoolNodeArray3D with null pointer");
  113.    for (i=0;i<xsize;i++) 
  114.     {
  115.      for (j=0;j<ysize;j++) free(p[i][j]);
  116.      free(p[i]);
  117.     }
  118.    free(p);
  119.   }
  120.  
  121. /**************************************|****************************************
  122. Routine   : GimmeATransformation"
  123. Input  par: none
  124. Output par: Transformation * (pointer to Transformation)
  125. Function  : Allocates a Transformation structure. Initializes Domain and Sub.
  126. ***************************************|***************************************/
  127.  
  128.  Transformation *GimmeATransformation(void)
  129.   {
  130.    Transformation *p=(Transformation *)malloc(sizeof(Transformation));
  131.    if (p==NULL) 
  132.    ErrorHandler(NO_FREE_MEMORY,"GimmeATransformation not able to allocate structure");
  133.    p->Domain=NULL; /* initialize */
  134.    p->Sub=NULL;
  135.    return p;
  136.   }
  137.  
  138. /**************************************|****************************************
  139. Routine   : FreeMeATransformation"
  140. Input  par: Transformation *Tr (pointer to Transformation) 
  141. Output par: none
  142. Function  : Frees a Transformation structure.
  143. ***************************************|***************************************/
  144.  
  145.  void FreeMeATransformation(Transformation *Tr)
  146.   {
  147.    if (Tr==NULL) ErrorHandler(NULL_POINTER,"FreeMeATransformation with null pointer");
  148.    free(Tr);
  149.   }
  150.  
  151. /**************************************|****************************************
  152. Routine   : GimmeATransArray"
  153. Input  par: int xsize (x size of transarray)
  154.             int ysize (y size of transarray)
  155. Output par: Transformation *** (pointer to 2D array of transformation-pointers)
  156. Function  : Allocates a 2D structure of transformationpointers. No Initializing.
  157. ***************************************|***************************************/
  158.  
  159.  
  160.  Transformation ****GimmeATransArray3D(int xsize,int ysize,int zsize)
  161.   {
  162.    int i,j;
  163.    Transformation ****Array;
  164.    
  165.    Array=(Transformation ****) calloc(xsize,sizeof(Transformation ***));
  166.    if (Array==NULL) 
  167.    ErrorHandler(NO_FREE_MEMORY,"GimmeATransArray3D not able to allocate struture");
  168.    for (i=0;i<xsize;i++)
  169.     {
  170.      Array[i]=(Transformation ***) calloc(ysize,sizeof(Transformation **));
  171.      if (Array[i]==NULL) 
  172.      ErrorHandler(NO_FREE_MEMORY,"GimmeATransArray3D not able to allocate structure");
  173.      for (j=0;j<ysize;j++)
  174.       {
  175.        Array[i][j]=(Transformation **) calloc(zsize,sizeof(Transformation *));
  176.        if (Array[i][j]==NULL) 
  177.        ErrorHandler(NO_FREE_MEMORY,"GimmeATransArray3D not able to allocate structure");
  178.       }
  179.     }
  180.    return Array;
  181.   }
  182.  
  183. /**************************************|****************************************
  184. Routine   : FreeMeATransArray"
  185. Input  par: TransArray *Tr (pointer to TransArray)
  186.             int xsize      (xsize of array) 
  187. Output par: none
  188. Function  : Frees a TransArray structure.
  189. ***************************************|***************************************/
  190.  
  191.  void FreeMeATransArray3D(Transformation ****Tr,int xsize,int ysize)
  192.   {
  193.    register unsigned int i,j;
  194.    
  195.    if (Tr==NULL) ErrorHandler(NULL_POINTER,"FreeMeATransArray3D with null pointer");
  196.    for (i=0;i<xsize;i++)
  197.     {
  198.      for (j=0;i<ysize;j++) free(Tr[i][j]);
  199.      free(Tr[i]);
  200.     }
  201.    free(Tr);
  202.   }
  203.  
  204. /**************************************|****************************************
  205. Routine   : GimmeAParameter"
  206. Input  par: none
  207. Output par: Parameter * (pointer to Parameter)
  208. Function  : Allocates a Parameter structure. No initializing.
  209. ***************************************|***************************************/
  210.  
  211.  Parameter *GimmeAParameter(void)
  212.   {
  213.    Parameter *p=(Parameter *)malloc(sizeof(Parameter));
  214.    if (p==NULL) 
  215.    ErrorHandler(NO_FREE_MEMORY,"GimmeAParameter not able to allocate structure");
  216.    return p;
  217.   }
  218.  
  219. /**************************************|****************************************
  220. Routine   : FreeMeAParameter"
  221. Input  par: Parameter *p (pointer to Parameter) 
  222. Output par: none
  223. Function  : Frees a Parameter structure.
  224. ***************************************|***************************************/
  225.  
  226.  void FreeMeAParameter(Parameter *p)
  227.   {
  228.    if (p==NULL) ErrorHandler(NULL_POINTER,"FreeMeAParameter with null pointer");
  229.    free(p);
  230.   }
  231.  
  232. /**************************************|****************************************
  233. Routine   : GimmeABitamap"
  234. Input  par: int xsize (x size of bitmap)
  235.             int ysize (y size of bitmap)
  236. Output par: BitMap *  (pointer to BitMap)
  237. Function  : Allocates a BitMap structure of size x,y. Initialize XSize=x 
  238.             YSize=y  Map->Gfx array  ImgType=type
  239.             Bitmap image is initialized to 0'oes.
  240. ***************************************|***************************************/
  241.  
  242.  BitMap *GimmeABitMap(int xsize, int ysize, int type)
  243.   {
  244.    int i;
  245.    BitMap *Gfx;
  246.    unsigned char **Array;
  247.    
  248.    Gfx=(BitMap *) malloc(sizeof(BitMap));
  249.    if (Gfx==NULL) 
  250.    ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap not able to allocate structure");
  251.    
  252.    Array=(unsigned char **) calloc(xsize,sizeof(unsigned char *));
  253.    if (Array==NULL) 
  254.    ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap not able to allocate structure");
  255.    for (i=0;i<xsize;i++)
  256.     {
  257.      Array[i]=(unsigned char *) calloc(ysize,sizeof(unsigned char));
  258.      if (Array[i]==NULL) 
  259.      ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap not able to allocate structure");
  260.     }
  261.    Gfx->Map=Array;  /* initialize */
  262.    Gfx->XSize=xsize;
  263.    Gfx->YSize=ysize;
  264.    Gfx->ImgType=type;
  265.    
  266.    return Gfx;
  267.   }
  268.  
  269. /**************************************|****************************************
  270. Routine   : FreeMeABitMap"
  271. Input  par: BitMap *Bm (pointer to BitMap) 
  272. Output par: none
  273. Function  : Frees a BitMap structure.
  274. ***************************************|***************************************/
  275.  
  276.  void FreeMeABitMap(BitMap *Bm)
  277.   {
  278.    register int i;
  279.    if (Bm==NULL) ErrorHandler(NULL_POINTER,"FreeMeABitMap with null pointer");
  280.    
  281.    for(i=0;i<Bm->XSize;i++) free(Bm->Map[i]);
  282.    free(Bm->Map);
  283.    free(Bm);
  284.   }
  285.  
  286.  
  287.  ListNode *GimmeAListNode(void)
  288.   {
  289.    ListNode *p=(ListNode *)malloc(sizeof(ListNode));
  290.    if (p==NULL) 
  291.    ErrorHandler(NO_FREE_MEMORY,"GimmeAListNode not able to allocate structure");
  292.    p->Info=0;
  293.    p->Domain=NULL; /* initialize */
  294.    p->Next=NULL; /* initialize */
  295.    p->Pred=NULL;
  296.    
  297.    return p;
  298.   }
  299.  
  300.  
  301.  BitMap3D *GimmeABitMap3D(int xsize, int ysize, int zsize, int type)
  302.   {
  303.    register int i,j;
  304.    BitMap3D *Gfx;
  305.    unsigned char ***Array;
  306.    
  307.    Gfx=(BitMap3D *) malloc(sizeof(BitMap3D));
  308.    if (Gfx==NULL) 
  309.    ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap3D not able to allocate structure");
  310.    
  311.    Array=(unsigned char ***) calloc(xsize,sizeof(unsigned char **));
  312.    if (Array==NULL) 
  313.    ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap3D not able to allocate structure");
  314.    for (i=0;i<xsize;i++)
  315.     {
  316.      Array[i]=(unsigned char **) calloc(ysize,sizeof(unsigned char*));
  317.      if (Array[i]==NULL) 
  318.      ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap3D not able to allocate structure");
  319.      for (j=0;j<ysize;j++)
  320.       {
  321.        Array[i][j]=(unsigned char *) calloc(zsize,sizeof(unsigned char));
  322.        if (Array[i][j]==NULL) 
  323.        ErrorHandler(NO_FREE_MEMORY,"GimmeABitMap3D not able to allocate structure");
  324.       }
  325.     }
  326.    Gfx->Map=Array;   /* initialize */
  327.    Gfx->XSize=xsize;
  328.    Gfx->YSize=ysize;
  329.    Gfx->ZSize=zsize;
  330.    Gfx->ImgType=type;
  331.    
  332.    return Gfx;
  333.   }
  334.  
  335. /**************************************|****************************************
  336. Routine   : FreeMeABitMap3D"
  337. Input  par: BitMap3D *Bm (pointer to BitMap3D) 
  338. Output par: none
  339. Function  : Frees a BitMap3D structure.
  340. ***************************************|***************************************/
  341.  
  342.  void FreeMeABitMap3D(BitMap3D *Bm)
  343.   {
  344.    register int i,j;
  345.    if (Bm==NULL) ErrorHandler(NULL_POINTER,"FreeMeABitMap3D with null pointer");
  346.    
  347.    for(i=0;i<Bm->XSize;i++) 
  348.     {
  349.      for(j=0;j<Bm->YSize;j++) free(Bm->Map[i][j]);
  350.      free(Bm->Map[i]);
  351.     }
  352.    free(Bm->Map);
  353.    free(Bm);
  354.   }
  355.  
  356.  
  357.  void FreeMeAListNode(ListNode *El)
  358.   {
  359.    if (El==NULL) ErrorHandler(NULL_POINTER,"FreeMeAListNode with null pointer");
  360.    free(El);
  361.   }
  362.  
  363.  void FreeMeAList(ListNode *LP)
  364.   {
  365.    ListNode *tmp2,*tmp=LP,*Start=LP;
  366.    if (LP==NULL) ErrorHandler(NULL_POINTER,"FreeMeAList with null pointer");
  367.    do 
  368.     {
  369.      tmp2=tmp;
  370.      tmp=tmp->Next;
  371.      FreeMeAListNode(tmp2);
  372.     }
  373.    while((tmp!=NULL) && (tmp!=Start));
  374.   }
  375.  
  376.  float *GimmeAFloatArray(int n) 
  377.   {
  378.    float *p=(float *)calloc(n,sizeof(float));
  379.    if (p==NULL) 
  380.    ErrorHandler(NO_FREE_MEMORY,"GimmeAFloatArray not able to allocate structure");
  381.    return p;
  382.   }
  383.  
  384.  void FreeMeAFloatArray(float *Pa)
  385.   {
  386.    if (Pa==NULL) 
  387.    ErrorHandler(NULL_POINTER,"FreeMeAFloatArray with null pointer");
  388.    free(Pa);
  389.   }
  390.  
  391.  long double *GimmeADoubleArray(int n) 
  392.   {
  393.    long double *p=(long double *)calloc(n,sizeof(long double));
  394.    if (p==NULL) 
  395.    ErrorHandler(NO_FREE_MEMORY,"GimmeADoubleArray not able to allocate structure");
  396.    return p;
  397.   }
  398.  
  399.  void FreeMeADoubleArray(double *Pa)
  400.   {
  401.    if (Pa==NULL) 
  402.    ErrorHandler(NULL_POINTER,"FreeMeADoubleArray with null pointer");
  403.    free(Pa);
  404.   }
  405.  
  406.  int *GimmeAIntArray(int n) 
  407.   {
  408.    int *p=(int *)calloc(n,sizeof(int));
  409.    if (p==NULL) ErrorHandler(NO_FREE_MEMORY,"GimmeAIntArray not able to allocate structure");
  410.    return p;
  411.   }
  412.  
  413.  void FreeMeAIntArray(int *Pa)
  414.   {
  415.    if (Pa==NULL) 
  416.    ErrorHandler(NULL_POINTER,"FreeMeAIntArray with null pointer");
  417.    free(Pa);
  418.   }
  419.  
  420.  unsigned int *GimmeAUIntArray(int n) 
  421.   {
  422.    unsigned int *p=(unsigned int *)calloc(n,sizeof(unsigned int));
  423.    if (p==NULL) 
  424.    ErrorHandler(NO_FREE_MEMORY,"GimmeAUIntArray not able to allocate structure");
  425.    return p;
  426.   }
  427.  
  428.  void FreeMeAUIntArray(unsigned int *Pa)
  429.   {
  430.    if (Pa==NULL) 
  431.    ErrorHandler(NULL_POINTER,"FreeMeAUIntArray with null pointer");
  432.    free(Pa);
  433.   }
  434.  
  435.  long *GimmeALongArray(int n) 
  436.   {
  437.    long *p=(long *)calloc(n,sizeof(long));
  438.    if (p==NULL) 
  439.    ErrorHandler(NO_FREE_MEMORY,"GimmeALongArray not able to allocate structure");
  440.    return p;
  441.   }
  442.  
  443.  void FreeMeALongArray(long *Pa)
  444.   {
  445.    if (Pa==NULL) 
  446.    ErrorHandler(NULL_POINTER,"FreeMeALongArray with null pointer");
  447.    free(Pa);
  448.   }
  449.  
  450.  unsigned long *GimmeAULongArray(int n) 
  451.   {
  452.    unsigned long *p=(unsigned long *)calloc(n,sizeof(unsigned long));
  453.    if (p==NULL) 
  454.    ErrorHandler(NO_FREE_MEMORY,"GimmeAULongArray not able to allocate structure");
  455.    return p;
  456.   }
  457.  
  458.  void FreeMeAULongArray(unsigned long *Pa)
  459.   {
  460.    if (Pa==NULL) 
  461.    ErrorHandler(NULL_POINTER,"FreeMeAULongArray with null pointer");
  462.    free(Pa);
  463.   }
  464.  
  465.  LimboHeader *GimmeALimboHeader(void) 
  466.   {
  467.    LimboHeader *p=(LimboHeader *)malloc(sizeof(LimboHeader));
  468.    if (p==NULL) 
  469.    ErrorHandler(NO_FREE_MEMORY,"GimmeALimboHeader not able to allocate structure");
  470.    return p;
  471.   }
  472.  
  473.  void FreeMeALimboHeader(LimboHeader *head)
  474.   {
  475.    if (head==NULL) 
  476.    ErrorHandler(NULL_POINTER,"FreeMeALimboHeader with null pointer");
  477.    free(head);
  478.   }
  479.  
  480.  
  481.  FeatureSpace *GimmeAFeatureSpace(int dim,int size)
  482.   {
  483.    FeatureSpace *S;
  484.    
  485.    S=(FeatureSpace *)malloc(sizeof(FeatureSpace));
  486.    if (S==NULL) 
  487.    ErrorHandler(NO_FREE_MEMORY,"GimmeAFeatureSpace not able to allocate structure");
  488.    S->Dimension=dim;
  489.    S->Size=size;
  490.    S->GridArray=GimmeAGrid(dim,size);
  491.    
  492.    return S;
  493.   }
  494.  
  495.  void FreeMeAFeatureSpace(FeatureSpace *S)
  496.   {
  497.    if (S==NULL) ErrorHandler(NULL_POINTER,"FreeMeAFeatureSpace with null pointer");
  498.    
  499.    if (S->GridArray!=NULL) FreeMeAGrid(S->GridArray,S->Dimension,S->Size);
  500.    free(S);
  501.   }
  502.  
  503.  Grid *GimmeAGrid(int dim,int size)
  504.   {
  505.    Grid *G=NULL;
  506.    GridTerm *GT;
  507.    register int i;
  508.    
  509.    if (dim>0) 
  510.     {
  511.      G=(Grid *)malloc(sizeof(Grid));
  512.      if (G==NULL) 
  513.      ErrorHandler(NO_FREE_MEMORY,"GimmeAGrid not able to allocate structure");
  514.      G->Next=(Grid **)calloc(size,sizeof(Grid *));
  515.      if (G->Next==NULL)
  516.      ErrorHandler(NO_FREE_MEMORY,"GimmeAGrid not able to allocate structure");
  517.      for (i=0;i<size;i++) G->Next[i]=GimmeAGrid(dim-1,size);
  518.     }
  519.    
  520.    if (dim==0)
  521.     {
  522.      GT=(GridTerm *)malloc(sizeof(GridTerm));
  523.      if (GT==NULL)
  524.      ErrorHandler(NO_FREE_MEMORY,"GimmeAGrid not able to allocate structure");
  525.      GT->Class=NULL;
  526.      GT->Count=0;
  527.      G=(Grid *)GT;
  528.     }
  529.    
  530.    return G;
  531.   }
  532.  
  533.  void FreeMeAGrid(Grid *G,int Dim,int Size)
  534.   {
  535.    register int i;
  536.    if (G==NULL)
  537.    ErrorHandler(NULL_POINTER,"FreeMeAGrid with null pointer");
  538.    
  539.    if(Dim>0)
  540.     {
  541.      if (G->Next!=NULL) 
  542.      for(i=0;i<Size;i++)
  543.       {
  544.        FreeMeAGrid(G->Next[i],Dim-1,Size);
  545.        free(G->Next[i]);
  546.       }
  547.     }
  548.    else 
  549.     {
  550.      if (G->Next!=NULL) 
  551.      for(i=0;i<Size;i++) free((GridTerm *)G->Next[i]);
  552.     }
  553.    free(G);
  554.   }
  555.  
  556.  
  557.